import requests

from common.config import getconf
from tests.ry_park_service.parking_tools import login_token


class TestCarData:

    # =====================车辆数据=====================

    #进场记录
    def queryEnter(self,env,plate="", chargeType=None, startTime="",endTime="",releaseType=None,current=1,size=10):
        base_url = getconf(env, "parking_service_url")
        url = base_url + "/v1/park/queryEnter"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": login_token(env)}
        dict = {
              "plate": plate,
              "chargeType": chargeType,
              "startTime": startTime,
              "endTime": endTime,
              "parkingSentryBoxId": getconf(env,"parkingSentryBoxId"),
              "releaseType": releaseType,   #1-自动放行 2-人工开闸 20-免费放行 10-补录
              "current": current,
              "size": size,

            }

        return requests.post(url, headers=headers, json=dict).json()

    # 出场记录
    def queryLeave(self, env, plate="", chargeType=None, startTime="", endTime="", releaseType=None, current=1,
                   size=10):
        base_url = getconf(env, "parking_service_url")
        url = base_url + "/v1/park/queryLeave"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": login_token(env)}
        dict = {
          "carChargeType": chargeType, #1-临时车 2-免费车 3-月租车
          "current": current,
          "endTime": endTime,
          "parkingSentryBoxId": getconf(env,"parkingSentryBoxId"),
          "plate": plate,
          "releaseType": releaseType,  #1-自动放行 2-人工开闸 20-免费放行
          "size": size,
          "startTime": startTime
        }

        return requests.post(url, headers=headers, json=dict).json()

    # 收费记录
    def queryCharge(self, env, plate="", chargeType=None, payStartTime="", payEndTime="",
                    payChannel=None,current=1,size=10):
        base_url = getconf(env, "parking_service_url")
        url = base_url + "/v1/park/queryCharge"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": login_token(env)}
        dict = {
              "chargeType": chargeType,  #1-临时车 2-免费车 3-月租车
              "current": current,
              "parkingSentryBoxId": getconf(env,"parkingSentryBoxId"),
              "payChannel": payChannel, #1-微信 2-支付宝 3-现金 0-其他
              "payEndTime": payEndTime,
              "payStartTime": payStartTime,
              "plate": plate,
              "size": size
            }

        return requests.post(url, headers=headers, json=dict).json()

    # 场内车辆
    def queryOnSite(self, env, plate="", chargeType=None, startTime="", endTime="", releaseType=None, current=1,
                   size=10):
        base_url = getconf(env, "parking_service_url")
        url = base_url + "/v1/park/queryOnSite"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": login_token(env)}
        dict = {
            "current": current,
            "parkingSentryBoxId": getconf(env, "parkingSentryBoxId"),
            "size": size
        }
        if plate:
            dict["plate"] = plate
        if chargeType:
            dict["chargeType"] = chargeType
        if releaseType:
            dict["releaseType"] = releaseType
        if startTime:
            dict["startTime"]=startTime
        if endTime:
            dict["endTime"] = endTime

        return requests.post(url, headers=headers, json=dict).json()

